package com.mxx.common.generator.convert;

import java.util.List;

public class NameOperator {


    public static String removeAll(String name, String[] prefixArray, String[] suffixArray) {
        return removePrefix(removeSuffix(name, suffixArray), prefixArray);
    }

    public static String removeAll(String name, List<String> prefixArray, List<String> suffixArray) {
        return removeAll(name, prefixArray.toArray(new String[0]), suffixArray.toArray(new String[0]));
    }

    public static String removePrefix(String name, String... prefixArray) {
        for (String prefix : prefixArray) {
            if (name.startsWith(prefix)) {
                return name.substring(prefix.length());
            }
        }
        return name;
    }

    public static String removeSuffix(String name, String... suffixArray) {
        for (String suffix : suffixArray) {
            if (name.endsWith(suffix)) {
                return name.substring(0, name.length() - suffix.length());
            }
        }
        return name;
    }

    public static String addAll(String name, String prefix, String suffix) {
        return addPrefix(addSuffix(name, suffix), prefix);
    }

    public static String addPrefix(String name, String prefix) {
        return prefix != null ? prefix + name : name;
    }

    public static String addSuffix(String name, String suffix) {
        return suffix != null ? name + suffix : name;
    }
}
